home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 …ember: Reference Library / Dev.CD Dec 96 RL / Dev.CD Dec 96 RL.toast / Technical Documentation / develop / develop Issue 28 / develop Issue 28 code / MacApp Debugging / IconEdit tests / IconEdit / UIconEdit.h < prev   
Encoding:
Text File  |  1996-08-25  |  12.6 KB  |  508 lines  |  [TEXT/MPS ]

  1. // IconEdit.h
  2. // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __UICONEDIT__
  5. #define __UICONEDIT__
  6.  
  7. // MacApp
  8.  
  9. #ifndef __UAPPLICATION__
  10. #include "UApplication.h"
  11. #endif
  12.  
  13. #ifndef __UCOMMAND__
  14. #include "UCommand.h"
  15. #endif
  16.  
  17. #ifndef __UFILEBASEDDOCUMENT__
  18. #include "UFileBasedDocument.h"
  19. #endif
  20.  
  21. #ifndef __UVIEW__
  22. #include "UView.h"
  23. #endif
  24.  
  25.  
  26. // Constants
  27. const OSType kSignature =    'ICED';             // Application signature
  28. const OSType kFileType =    'ICON';             // File-type for document files created by this application
  29.  
  30. // definitions for the custom apple event suite
  31. const OSType kAEIconEditClass         = 'ICED';        // event class
  32.  
  33. const OSType kAEInvertID             = 'INVT';        // event IDs
  34. const OSType kAEZoomInID             = 'ZmIn';
  35. const OSType kAEZoomOutID             = 'ZmOt';
  36. const OSType kAEDrawPoints             = 'DrPt';
  37.  
  38. const AEKeyword keyPointList         = 'kPtL';
  39. const AEKeyword keyErasePoints         = 'kErs';
  40.  
  41. // Forward references
  42. class TIconBitMap;
  43. class TIconEditView;
  44.  
  45. extern short gSpecialDocCount;    //Added by CKopala 8/24/96
  46.  
  47. // Classes
  48. // ====================================================================================
  49.  
  50. class TIconEditApplication : public TApplication
  51. {
  52.     MA_DECLARE_CLASS;
  53.  
  54.   public:
  55.     virtual ~TIconEditApplication();
  56.         // Destructor
  57.     
  58.     virtual void IIconEditApplication();
  59.  
  60.     virtual TDocument* DoMakeDocument(CommandNumber itsCommandNumber, TFile* itsFile); // Override
  61.     virtual MScriptableObject* TIconEditApplication::GetContainedObject(DescType desiredType,
  62.                                                     DescType selectionForm,const CAEDesc& selectionData);
  63.                                                     
  64.     virtual TView* MakeViewForAlienClipboard(); // Override
  65.         //  Makes a view of type TIconEditView for the Clipboard if the public desk
  66.         //    scrap contains data of type 'ICON'.  Otherwise it calls INHERITED
  67.         //    MakeViewForAlienClipboard. 
  68. };
  69.  
  70. // ====================================================================================
  71. //old class TIconDocument : public TDocument
  72.  
  73. class TIconDocument : public TFileBasedDocument //new
  74. {
  75.     MA_DECLARE_CLASS;
  76.  
  77.   protected:
  78.     TIconBitMap*    fIconBitMap;    // The icon's bit map
  79.     TIconEditView*    fIconView;        // a reference to the single view in this window
  80.     CRGBColor        fColor;            // color property of the document
  81.  
  82.   public:
  83.     TIconDocument();    
  84.         // Constructor
  85.         
  86.     void IIconDocument(TFile* itsDocument);
  87.     
  88.     virtual ~TIconDocument();
  89.  
  90.     virtual void DoInitialState(); // Override
  91.  
  92.     virtual void DoMakeViews(Boolean forPrinting); // Override
  93.  
  94.     virtual void DoMenuCommand(CommandNumber aCommandNumber); 
  95.     
  96.     virtual void DoScriptCommand(CommandNumber aCommand,
  97.                                 TAppleEvent* message,
  98.                                 TAppleEvent* reply);    // Override
  99.  
  100.     virtual void DoSetupMenus(); // Override
  101.  
  102.     
  103.  
  104.     virtual void DoNeedDiskSpace(TFile* itsDocument, 
  105.                                  long& dataForkBytes, 
  106.                                  long& rsrcForkBytes); // Override
  107.  
  108.     virtual void DoRead(TFile* itsDocument, Boolean forPrinting); // Override
  109.  
  110.     virtual void DoWrite(TFile* itsDocument, Boolean makingCopy); // Override
  111.     
  112.     virtual void InvertIcon();
  113.     
  114.     TIconEditView* GetIconView();
  115.  
  116.     virtual void ClearIcon();
  117.  
  118.     virtual void SetIcon(TIconBitMap* newIcon);
  119.     
  120.     virtual TIconBitMap* ReturnBitMap();
  121.     
  122.     virtual void RedrawViews();
  123.     
  124.     virtual void GetSetPropertyInfo(DescType whichProperty, 
  125.                                     CommandNumber& cmdNum,
  126.                                     Boolean& canUndo,
  127.                                     Boolean& causesChange,
  128.                                     TCommandHandler*& theContext); // Override
  129.     
  130.     virtual void SetObjectProperty(const CAEDesc& thePropertyValue,
  131.                                    DescType whichProperty); // Override
  132.                             
  133.     virtual Boolean GetObjectProperty(CAEDesc& thePropertyValue,
  134.                                       DescType whichProperty,
  135.                                       const CAEDesc& desiredType);
  136.         // Override
  137.         
  138.     virtual CRGBColor GetIconColor();
  139.     
  140.     virtual void SetIconColor(CRGBColor& newColor);
  141.     
  142. };
  143.  
  144.  
  145. // ====================================================================================
  146.  
  147. class TIconEditView :    public TView
  148. {
  149.     MA_DECLARE_CLASS;
  150.  
  151.   protected:
  152.     short            fMagnification;        // No. of times to magnify the icon.
  153.     TIconDocument    *fIconDocument;        // Reference to the view's icon document.
  154.  
  155.   public:
  156.     TIconEditView(); 
  157.         // Constructor
  158.     
  159.     virtual ~TIconEditView();
  160.         // Destructor
  161.     
  162.     virtual void IIconEditView(TDocument* itsDocument,
  163.                                TView* itsSuperView,
  164.                                const VPoint& itsLocation,
  165.                                short itsMagnification);
  166.                                       
  167.     virtual void DoPostCreate(TDocument* itsDocument); // Override
  168.  
  169.     virtual void CalcMinFrame(VRect& minFrame); // Override
  170.  
  171.     virtual Boolean ContainsClipType(ResType aType); // Override
  172.         //  Called when a view of this type is installed in the Clipboard.
  173.         //    Returns true if aType is kIconClipType (i.e. 'ICON'). 
  174.  
  175.     virtual void DoKeyEvent(TToolboxEvent* info); // Override
  176.         //  Treats the backspace the same as the Clear command. 
  177.         
  178.     virtual void DoMenuCommand(CommandNumber aCommandNumber); // Override
  179.  
  180.     virtual void DoMouseCommand(VPoint& theMouse,
  181.                                 TToolboxEvent* event,
  182.                                 CPoint hysteresis); // Override
  183.  
  184.     virtual void DoSetCursor(const VPoint& localPoint,
  185.                              RgnHandle cursorRegion); // Override
  186.  
  187.     virtual void DoSetupMenus(); // Override
  188.  
  189.     virtual void Draw(const VRect& area); // Override
  190.  
  191.     virtual void DrawBit(VPoint theBit, Boolean turnBitOn, CRGBColor& drawingColor); 
  192.  
  193.     virtual Boolean PointToBit(const VPoint& thePoint, VPoint& iconBit);
  194.  
  195.     virtual short GetMagnification();
  196.  
  197.     virtual void SetMagnification(short magnification);
  198.  
  199.     virtual void WriteToDeskScrap();    // Override
  200. };
  201.  
  202. // ====================================================================================
  203.  
  204. class TDrawPointsAppleEvent : public TAppleEvent
  205. {
  206.     MA_DECLARE_CLASS;
  207.  
  208.   public:
  209.     TDrawPointsAppleEvent();
  210.     
  211.     virtual ~TDrawPointsAppleEvent();
  212.         // Destructor
  213.     
  214.     void IDrawPointsAppleEvent(    MScriptableObject     *itsDirectObject,
  215.                                 TIconBitMap            *iconBitMapModel,
  216.                                 const Boolean        turnBitsOn);
  217. };
  218.  
  219. // ====================================================================================
  220.  
  221. class TDrawPointsCommand : public TCommand
  222. {
  223.     MA_DECLARE_CLASS;
  224.  
  225.   protected:
  226.     TIconBitMap        *fSavedBitMap;
  227.     TIconDocument    *fIconDocument;    // The document affected by this command.
  228.     Boolean            fErasePoints;
  229.     TDynamicArray    *fPointList;    // list of points to set or unset
  230.  
  231.   public:
  232.     TDrawPointsCommand();
  233.         // Constructor
  234.  
  235.     virtual void IDrawPointsCommand(TIconDocument *itsIconDocument,
  236.                                     TAppleEvent *theAppleEvent);
  237.     
  238.     virtual void DoIt();     // Override
  239.  
  240.     virtual void RedoIt();     // Override
  241.  
  242.     virtual void UndoIt();     // Override
  243.     
  244.     virtual ~TDrawPointsCommand();
  245. };
  246.  
  247. // ====================================================================================
  248.  
  249. class TSetColorCommand : public TCommand
  250. {
  251.     MA_DECLARE_CLASS;
  252.  
  253.   protected:
  254.     CRGBColor        fOldColor;
  255.     CRGBColor        fNewColor;
  256.  
  257.   public:
  258.     TSetColorCommand();
  259.         // Constructor
  260.     
  261.     virtual ~TSetColorCommand();
  262.         // Destructor
  263.         
  264.     virtual void ISetColorCommand(    TIconDocument    *itsIconDocument, 
  265.                                     CRGBColor&         newColor);
  266.     
  267.     virtual void DoIt();        // Override
  268.     
  269.     virtual void RedoIt();        // Override
  270.     
  271.     virtual void UndoIt();        // Override
  272. };
  273.  
  274.  
  275. // ====================================================================================
  276.  
  277. class TInvertCommand : public TCommand
  278. {
  279.     MA_DECLARE_CLASS;
  280.  
  281.   protected:
  282.     TIconDocument    *fIconDocument;        // The document affected by this command.
  283.     
  284.   public:
  285.     TInvertCommand();
  286.         // Constructor
  287.     
  288.     virtual ~TInvertCommand();
  289.         // Destructor
  290.  
  291.     virtual void IInvertCommand(TIconDocument* itsIconDocument);
  292.     
  293.     virtual TAppleEvent * MakeAppleEvent();
  294.  
  295.  
  296.     virtual void DoIt(); // Override
  297.  
  298.     virtual void RedoIt(); // Override
  299.  
  300.     virtual void UndoIt(); // Override
  301. };
  302.  
  303.  
  304. // ====================================================================================
  305.  
  306. class TIconDrawCommand : public TTracker
  307. {
  308.     MA_DECLARE_CLASS;
  309.  
  310.   protected:
  311.     TIconDocument    *fIconDocument;            // The document affected by this command.
  312.     TIconEditView    *fIconEditView;            // The view in which this command draws.
  313.     TIconBitMap        *fIconBitMap;            // The icon in which drawing takes place.
  314.     TIconBitMap        *fIconBitMapModel;        // Model used to generate apple events
  315.     TIconBitMap        *fOriginalIcon;            // A copy of the original icon.
  316.     Boolean            fTurnBitsOn;            // Whether to draw bits black or white.
  317.     CRGBColor        fColor;                    // drawing color (property of fDocument)
  318.     
  319.   public:
  320.     TIconDrawCommand();
  321.         // Constructor
  322.  
  323.     virtual void IIconDrawCommand(TIconEditView* itsIconEditView, 
  324.                                   TIconDocument* itsIconDocument, 
  325.                                   VPoint& theMouse);
  326.  
  327.     virtual ~TIconDrawCommand();
  328.     
  329.     virtual void DoIt(); // Override
  330.         //  Sets the fIconDocument's icon bitmap to that of fIconBitMap by calling
  331.         //    the document's SetIcon method. Validates the edit view to avoid
  332.         //    flashing.     
  333.  
  334.     virtual void RedoIt(); // Override
  335.     
  336.     virtual void TrackConstrain(TrackPhase        aTrackPhase, 
  337.                                const VPoint&    anchorPoint, 
  338.                                const VPoint&    previousPoint,
  339.                                VPoint&            nextPoint, 
  340.                                Boolean            mouseDidMove); 
  341.  
  342.     virtual void TrackFeedback(TrackPhase        aTrackPhase,
  343.                                const VPoint&    anchorPoint, 
  344.                                const VPoint&    previousPoint, 
  345.                                const VPoint&    nextPoint, 
  346.                                Boolean            mouseDidMove, 
  347.                                Boolean            turnItOn); 
  348.  
  349.     virtual TTracker* TrackMouse(TrackPhase    aTrackPhase, 
  350.                                         VPoint&        anchorPoint, 
  351.                                         VPoint&        previousPoint, 
  352.                                         VPoint&        nextPoint, 
  353.                                         Boolean        mouseDidMove); 
  354.  
  355.     virtual void UndoIt(); // Override
  356.         //  Sets the fIconDocument's icon bitmap to that of fOriginalIcon by calling
  357.         //    the document's SetIcon method. 
  358.  
  359. };
  360.  
  361.  
  362. // ====================================================================================
  363.  
  364. class TIconEditCommand : public TCommand
  365. {
  366.     MA_DECLARE_CLASS;
  367.  
  368.   protected:
  369.     TIconDocument    *fIconDocument;            // The document affected by this command.
  370.     TIconEditView    *fIconEditView;            // The view in which this command draws.
  371.     TIconBitMap        *fSavedBitMap;            // Saved state for undo/redo
  372.     
  373.   public:
  374.     TIconEditCommand();
  375.         // Constructor
  376.  
  377.     virtual void IIconEditCommand(CommandNumber    itsCommandNumber, 
  378.                                   TIconEditView*    itsIconEditView,
  379.                                   TIconDocument*    itsIconDocument);
  380.     virtual ~TIconEditCommand();
  381.     
  382.     virtual void DoIt(); // Override
  383.     
  384.     virtual void RedoIt(); // Override
  385.     
  386.     virtual void UndoIt(); // Override
  387. };
  388.  
  389.  
  390. // ====================================================================================
  391.  
  392. class TIconPasteCommand : public TCommand
  393. {
  394.     MA_DECLARE_CLASS;
  395.  
  396.   protected:            
  397.     TIconDocument    *fIconDocument;            // The document affected by this command.
  398.     TIconEditView    *fIconEditView;            // The view in which this command draws.
  399.     TIconBitMap        *fSavedIcon;            // Temporary saved icon
  400.  
  401.   public:
  402.     TIconPasteCommand();
  403.             // Constructor
  404.  
  405.     virtual void IIconPasteCommand(TIconEditView* itsIconEditView,
  406.                                    TIconDocument* itsIconDocument);
  407.     virtual ~TIconPasteCommand();
  408.     
  409.     virtual void DoIt(); // Override
  410.         
  411.     virtual void UndoIt(); // Override
  412. };
  413.  
  414.  
  415. // ====================================================================================
  416.  
  417. class TIconBitMap : public TObject
  418. {
  419.     MA_DECLARE_CLASS;
  420.  
  421.   protected:
  422.     Handle        fDataHandle;            // Handle to the icon's data.
  423.     
  424.   public:
  425.     TIconBitMap();
  426.         // Constructor
  427.     
  428.     virtual void IIconBitMap();
  429.  
  430.     virtual ~TIconBitMap();
  431.     
  432.     virtual void SetIconBitMap(Handle theBitMap);
  433.     
  434.     virtual void ReadFrom(TStream* aStream); // Override
  435.  
  436.     virtual void WriteTo(TStream* aStream); // Override
  437.  
  438.     virtual void LoadFromScrap();
  439.  
  440.     virtual void WriteToScrap();
  441.  
  442.     virtual TIconBitMap* Copy();
  443.  
  444.     virtual void CopyDataTo(TIconBitMap* anIcon);
  445.  
  446.     virtual void Clear();
  447.  
  448.     virtual void Invert();
  449.  
  450.     virtual void Draw(const CRect& area, const CRGBColor& drawingColor); //not Override!
  451.  
  452.     virtual Boolean GetBit(VPoint iconBit);
  453.  
  454.     virtual void SetBit(VPoint iconBit, Boolean turnBitOn);
  455.  
  456.     virtual void IconBitToByteBit(VPoint iconBit, short& byte, short& bit);
  457. };
  458. // ====================================================================================
  459. class TZoomOutCommand : public TCommand
  460. {
  461.     MA_DECLARE_CLASS;
  462.     
  463.   public:
  464.     TIconDocument    *fIconDocument;        // The document affected by this command.
  465.     TZoomOutCommand();
  466.         // Constructor
  467.     
  468.     virtual ~TZoomOutCommand();
  469.         // Destructor
  470.  
  471.     virtual void IZoomOutCommand(TIconDocument* itsIconDocument); //, TAppleEvent* theAppleEvent);
  472.  
  473.     virtual void DoIt(); // Override
  474.  
  475.     virtual void RedoIt(); // Override
  476.  
  477.     virtual void UndoIt(); // Override
  478.     
  479.     virtual TAppleEvent* MakeAppleEvent();
  480.  
  481. };
  482. // ====================================================================================
  483. class TZoomInCommand : public TCommand
  484. {
  485.     MA_DECLARE_CLASS;
  486.     
  487.   public:
  488.     TIconDocument    *fIconDocument;        // The document affected by this command.
  489.     TZoomInCommand();
  490.         // Constructor
  491.     
  492.     virtual ~TZoomInCommand();
  493.         // Destructor
  494.  
  495.     virtual void IZoomInCommand(TIconDocument* itsIconDocument); //, TAppleEvent* theAppleEvent);
  496.  
  497.     virtual void DoIt(); // Override
  498.  
  499.     virtual void RedoIt(); // Override
  500.  
  501.     virtual void UndoIt(); // Override
  502.     
  503.     virtual TAppleEvent* MakeAppleEvent();
  504.  
  505. };
  506.  
  507. #endif
  508.